/*
 * @lc app=leetcode.cn id=667 lang=cpp
 *
 * [667] 优美的排列 II
 */

#include <iostream>
#include <vector>
using namespace std;

// @lc code=start
class Solution {
   public:
    vector<int> constructArray(int n, int k) {
        vector<int> result;

        // 构造公差为1的等差数列，范围[1, n-k-1]，占用1个k值
        for (int i = 1; i <= n - k - 1; i++) {
            result.push_back(i);
        }

        // 构造交错数列，范围[n-k, n]，占用k-1个k值
        int left = n - k;
        int right = n;
        int flag = 1;
        for (int i = n - k; i <= n; i++) {
            if (flag == 1) {
                result.push_back(left++);
            } else {
                result.push_back(right--);
            }
            flag = 1 - flag;
        }

        // 返回结果
        return result;
    }
};
// @lc code=end
